cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
project(3dstool)
if(MSVC_VERSION EQUAL 1700 AND MSVC_IDE)
  set(CMAKE_GENERATOR_TOOLSET "v110_xp" CACHE STRING "Name of generator toolset." FORCE)
endif()
if(MSVC_VERSION EQUAL 1800 AND MSVC_IDE)
  set(CMAKE_GENERATOR_TOOLSET "v120_xp" CACHE STRING "Name of generator toolset." FORCE)
endif()
if(MSVC_VERSION EQUAL 1900 AND MSVC_IDE)
  set(CMAKE_GENERATOR_TOOLSET "v140_xp" CACHE STRING "Name of generator toolset." FORCE)
endif()
if(MSVC_VERSION GREATER 1909 AND MSVC_VERSION LESS 1920 AND MSVC_IDE)
  set(CMAKE_GENERATOR_TOOLSET "v141_xp" CACHE STRING "Name of generator toolset." FORCE)
endif()
if(MSVC_VERSION GREATER 1600 AND NOT MSVC_IDE)
  if(CMAKE_SIZEOF_VOID_P EQUAL 8)
    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:CONSOLE,5.02")
  else()
    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:CONSOLE,5.01")
  endif()
endif()
if(APPLE)
  set(CMAKE_MACOSX_RPATH 1)
endif()
set(_3DSTOOL_MAJOR 1)
set(_3DSTOOL_MINOR 2)
set(_3DSTOOL_PATCHLEVEL 6)
if(NOT MSVC_IDE AND NOT XCODE_VERSION AND NOT CMAKE_BUILD_TYPE)
  set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel." FORCE)
endif()
option(BUILD64 "Build x86_64(unix only)" ON)
if(MSVC OR APPLE OR (NOT CYGWIN AND NOT MINGW))
  option(USE_DEP "Use prebuilt dep" ON)
endif()
set(CMAKE_INSTALL_PREFIX "${PROJECT_SOURCE_DIR}")
set(ROOT_SOURCE_DIR "${PROJECT_SOURCE_DIR}")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${ROOT_SOURCE_DIR}/cmake")
include(AddCompilationFlags)
include(AddDep)
include(AddTarget)
include(AutoFiles)
ADD_COMPILATION_FLAGS()
if(USE_DEP)
  ADD_DEP_INCLUDE_DIR("${ROOT_SOURCE_DIR}/dep")
  ADD_DEP_LIBRARY_DIR("${ROOT_SOURCE_DIR}/dep")
endif()
if(UNIX OR MINGW)
  if(CYGWIN)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
  else()
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
    if(NOT APPLE)
      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc -static-libstdc++")
    endif()
  endif()
  if((UNIX AND BUILD64) OR (MINGW AND CMAKE_SIZEOF_VOID_P EQUAL 8))
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m64")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m64")
  else()
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32")
  endif()
endif()
if(MSVC_IDE OR XCODE_VERSION)
  set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/bin")
else()
  set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/bin/${CMAKE_BUILD_TYPE}")
endif()
add_definitions(-D_3DSTOOL_VERSION="${_3DSTOOL_MAJOR}.${_3DSTOOL_MINOR}.${_3DSTOOL_PATCHLEVEL}")
if(WIN32)
  add_definitions(-D_CRT_SECURE_NO_WARNINGS)
endif()
if(UNIX OR MINGW)
  add_definitions(-D_FILE_OFFSET_BITS=64)
  add_definitions(-Wno-multichar -Wno-shift-overflow -Wno-unused-result)
  set(CMAKE_INSTALL_RPATH .)
  set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
endif()
add_subdirectory(src)
